<?php

namespace app\api\controller;

use app\data\Data;

class Authentication extends Index
{
    /**
     * 个人认证首页
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function authentication_personal()
    {
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $username = (isset($_GET['username']) && !empty($_GET['username']) ? $_GET['username'] : null);
        $logmin = (isset($_GET['logmin']) && $_GET['logmin']) ? strtotime($_GET['logmin']) : 0;
        $logmax = (isset($_GET['logmax']) && $_GET['logmax']) ? (strtotime($_GET['logmax']) + 24 * 60 * 60 - 1) : time();

        $where['static'] = (isset($_GET['static']) && $_GET['static']) ? $_GET['static'] : array('neq', 0);
        $where['nick|phone|alipay'] = array('like', "%$username%");
        $where['time'] = array(array('egt', $logmin), array('elt', $logmax), 'and');
//
        $res['data'] = db('authentication_personal')->where($where)->limit(10)->page($page)->select();
        $res['count'] = db('authentication_personal')->where($where)->count();
        if (isset($res) || !empty($res)) {
            $this->_jsonp('200', '个人认证信息获取成功', $res);
        } else {
            $this->_jsonp('1000', '个人认证信息获取失败', null);
        }
    }

    /**
     * 个人认证
     * 详情页
     */
    public function authentication_personal_msg()
    {
        $where['id'] = trim(input('get.id'));

        $res = db('authentication_personal')->where($where)->find();
        if (isset($res) || !empty($res)) {
            $this->_jsonp('200', '获取成功', $res);
        } else {
            $this->_jsonp('1000', '获取失败', null);
        }
    }


    /**
     * 个人认证
     * 修改审核
     * 通过
     */
    public function personal_pass()
    {
        $id = trim(input('get.id'));
        $data['static'] = 2;
        $where['id'] = explode(",", $id);
        for ($i = 0; $i < count($where['id']); $i++) {
            $res = db('authentication_personal')->where('id', $where['id'][$i])->update($data);
        }
        if (isset($res) || !empty($res)) {
            action_log('个人认证审核通过', 'log_admin', 1);
            $this->_jsonp('200', '修改成功', $res);
        } else {
            action_log('个人认证审核通过', 'log_admin');
            $this->_jsonp('1000', '修改失败', null);
        }
    }

    /**
     * 个人认证
     * 修改审核
     * 不通过
     */
    public function personal_nopass()
    {
        $where['id'] = trim(input('get.id'));
        $data['static'] = 3;
        $data['result'] = (isset($_GET['result']) && $_GET['result']) ? trim($_GET['result']) : '';
        $zgh_authentication_personal = new Data('authentication_personal');
        $res = $zgh_authentication_personal->_update($data, $where);
        if (isset($res) || !empty($res)) {
            action_log('个人认证审核不通过', 'log_admin', 1);
            $this->_jsonp('200', '修改成功', $res);
        } else {
            action_log('个人认证审核不通过', 'log_admin');
            $this->_jsonp('1000', '修改失败', null);
        }
    }


    /**
     * 企业认证首页
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function authentication_enterprise()
    {
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $username = (isset($_GET['username']) && !empty($_GET['username']) ? $_GET['username'] : null);
        $logmin = (isset($_GET['logmin']) && $_GET['logmin']) ? strtotime($_GET['logmin']) : 0;
        $logmax = (isset($_GET['logmax']) && $_GET['logmax']) ? (strtotime($_GET['logmax']) + 24 * 60 * 60 - 1) : time();

        $where['static'] = (isset($_GET['static']) && $_GET['static']) ? $_GET['static'] : array('neq', 0);
        $where['company_name|nick|phone'] = array('like', "%$username%");
        $where['time'] = array(array('egt', $logmin), array('elt', $logmax), 'and');

        $zgh_authentication_enterprise = new Data('authentication_enterprise');
        $res['data'] = $zgh_authentication_enterprise->selectPage($page, $where);
        $res['count'] = $zgh_authentication_enterprise->count($where);
        if (isset($res) || !empty($res)) {
            $this->_jsonp('200', '获取企业认证信息成功', $res);
        } else {
            $this->_jsonp('1000', '获取企业认证信息失败', null);
        }
    }

    /**
     * 企业认证
     * 详细信息
     */
    public function authentication_enterprise_msg()
    {
        $where['id'] = trim(input('get.id'));
        $zgh_authentication_enterprise = new  Data('authentication_enterprise');
        $res = $zgh_authentication_enterprise->_find($where);
        if (isset($res) || !empty($res)) {
            $this->_jsonp('200', '获取成功', $res);
        } else {
            $this->_jsonp('1000', '获取失败', null);
        }
    }

    /**
     * 企业认证
     * 修改审核
     * 通过
     */

    public function enterprise_pass()
    {
        $where['id'] = trim(input('get.id'));
        $data['static'] = 2;
        $zgh_authentication_enterprise = new Data('authentication_enterprise');
        $res = $zgh_authentication_enterprise->_update($data, $where);
        if (isset($res) || !empty($res)) {
            action_log('企业认证审核通过', 'log_admin', 1);
            $this->_jsonp('200', '成功', $res);
        } else {
            action_log('企业认证审核通过', 'log_admin');
            $this->_jsonp('1000', '失败', null);
        }
    }

    /**
     * 企业认证
     * 修改审核
     * 不通过
     */
    public function enterprise_nopass()
    {
        $where['id'] = trim(input('get.id'));
        $data['static'] = 3;
        $data['result'] = (isset($_GET['result']) && $_GET['result']) ? trim($_GET['result']) : '';
        $zgh_authentication_enterprise = new Data('authentication_enterprise');
        $res = $zgh_authentication_enterprise->_update($data, $where);
        if (isset($res) || !empty($res)) {
            action_log('企业认证审核不通过', 'log_admin', 1);
            $this->_jsonp('200', '成功', $res);
        } else {
            action_log('企业认证审核不通过', 'log_admin');
            $this->_jsonp('1000', '失败', null);
        }
    }
}
